package org.dtrd.modules.organization.entity.po;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.common.util.DateUtils;
import org.dtrd.modules.dict.service.IDtrdEntRdDicDistrictService;
import org.dtrd.modules.organization.entity.bean.OrganizationDetail;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.ParseException;
import java.util.Date;
import java.util.Optional;
import java.util.StringJoiner;


/**
 * <p>
 * 机构表
 * </p>
 *
 * @author QR
 * @since 2021-12-14
 */
@Getter
@Setter
@TableName("dtrd_ent_rd_organization")
public class DtrdEntRdOrganization {

    @TableId(value = "data_id", type = IdType.AUTO)
    private Integer dataId;

    /**
     * 机构编码
     */
    @TableField("org_code")
    private String organizationCode;

    @TableField("org_icon")
    private String orgIcon;

    /**
     * 机构名称
     */
    @TableField("org_name")
    private String organizationName;

    /**
     * 机构地址
     */
    @TableField("org_address")
    private String organizationAddress;

    /**
     * 机构等级
     */
    @TableField("org_level")
    private Integer organizationLevel;

    /**
     * 营业时间_开始
     */
    @TableField("opening_time")
    private Date openingTime;

    /**
     * 营业时间_结束
     */
    @TableField("closed_time")
    private Date closedTime;

    /**
     * 机构联系电话
     */
    @TableField("org_phone")
    private String organizationPhone;

    /**
     * 机构简介图
     */
    @TableField("org_thumb")
    private String orgThumb;

    /**
     * 机构地址省id
     */
    @TableField("org_province_id")
    private Integer organizationProvinceId;

    /**
     * 机构地址市id
     */
    @TableField("org_city_id")
    private Integer organizationCityId;

    /**
     * 机构地址地区id
     */
    @TableField("org_area_id")
    private Integer organizationAreaId;

    /**
     * 机构介绍
     */
    @TableField("org_introduce")
    private String organizationIntroduce;

    @TableField("create_time")
    private Date createTime;

    @TableField("is_del")
    @TableLogic
    private Integer isDel;

    public DtrdEntRdOrganization init() {
        createTime = new Date();
        isDel = 0;
        return this;
    }

    public DtrdEntRdOrganization parseFromDto(OrganizationDetail dto) {
        dataId = dto.getDataId();
        organizationCode = dto.getOrganizationCode();
        organizationName = dto.getOrganizationName();
        organizationLevel = dto.getOrganizationLevel();
        organizationProvinceId = dto.getOrganizationProvinceId();
        organizationCityId = dto.getOrganizationCityId();
        organizationAreaId = dto.getOrganizationAreaId();
        orgIcon = dto.getOrgIcon();
//        try {
//            openingTime = DateUtils.parseDate(dto.getOpeningTime(), DateUtils.short_time_sdf.get().toPattern());
//            closedTime = DateUtils.parseDate(dto.getClosedTime(), DateUtils.short_time_sdf.get().toPattern());
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
        // TODO 查询出provinceId对应的文本，和 organizationAddress 拼接到一块
        organizationAddress = dto.getOrganizationAddress();
        organizationPhone = dto.getOrganizationPhone();
        organizationIntroduce = dto.getOrganizationIntroduce();
        return this;
    }


}
